package com.design.YiTong.virus.controller;

import com.design.YiTong.common.result.Result;
import com.design.YiTong.model.virus.VirusInfo;
import com.design.YiTong.virus.repository.VirusRepository;
import com.design.YiTong.virus.service.virusService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/admin/virus")
public class VirusController {
    @Autowired
    private virusService virusservice;
    @Autowired
    private VirusRepository virusRepository;
    @ApiOperation("毒株查询")
    @GetMapping("/find")
    public Result findVirus(){
        List<VirusInfo> lst = virusservice.searchVirus();
        return Result.ok(lst);
    }
    @ApiOperation("毒株修改")
    @PostMapping("/save")
    public Result saveVirus(@RequestBody VirusInfo virusInfo){
        virusservice.saveVirus(virusInfo);
        return Result.ok();
    }
    @ApiOperation("删除信息")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable String id){
        virusRepository.deleteById(id);
        return Result.ok();
    }
    @ApiOperation("根据id查询")
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable String id){
        Optional<VirusInfo> virusInfo= virusRepository.findById(id);
        return Result.ok(virusInfo.get());
    }
}
